package star.查找算法.第一个出现一次的字符;

import java.util.LinkedHashMap;
import java.util.Map;

public class FirstUniqChar {
    public static void main(String[] args) {
        String s = "leetcode";
        System.out.println(new FirstUniqChar().firstUniqChar(s));
    }
    public char firstUniqChar(String s) {
        Map<Character, Integer> dic = new LinkedHashMap<>();
        char[] sc = s.toCharArray();
        for(char c : sc){
            if (!dic.containsKey(c)) dic.put(c,1);
            else dic.put(c, dic.get(c)+1);
        }
        for(Map.Entry<Character, Integer> d : dic.entrySet()){
            if(d.getValue()==1) return d.getKey();
        }
        return ' ';
    }
}
